library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.4 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 2.0.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(p8105.datasets)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggridges)
library(flexdashboard)
data("rest_inspec")
head(rest_inspec)
## # A tibble: 6 × 18
## action boro building camis critical_flag cuisine_descrip… dba
## <chr> <chr> <chr> <int> <chr> <chr> <chr>
## 1 Violations we… MANHA… 425 4.15e7 Not Critical Italian SPINELLI…
## 2 Violations we… MANHA… 37 4.12e7 Critical Korean SHILLA K…
## 3 Violations we… MANHA… 15 4.11e7 Not Critical Café/Coffee/Tea CITY PERK
## 4 Violations we… MANHA… 35 4.13e7 Critical Korean MADANGSUI
## 5 Violations we… MANHA… 1271 5.00e7 Critical American THE HARO…
## 6 Violations we… MANHA… 155 5.00e7 Not Critical Donuts DUNKIN D…
## # … with 11 more variables: inspection_date <dttm>, inspection_type <chr>,
## # phone <chr>, record_date <dttm>, score <int>, street <chr>,
## # violation_code <chr>, violation_description <chr>, zipcode <int>,
## # grade <chr>, grade_date <dttm>
## filter or randomly sample from the complete dataset
rest_inspec_df =
rest_inspec %>%
select(boro,critical_flag,cuisine_description,score,grade) %>%
filter(!is.na(score),!is.na(grade),cuisine_description=="Italian")
## boxplot
box_df =
rest_inspec_df %>%
ggplot(aes(x = boro, y = score, fill = boro)) +
geom_boxplot() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(box_df)